import javax.jms.MessageListener
import org.springframework.jms.listener.adapter.MessageListenerAdapter

// Place your Spring DSL code here
/*

context.GrailsContextLoader Error executing bootstraps: Error creating bean with name 'customerXFire': Cannot resolve reference to bean 'customerService' while setting bean property 'serviceBean'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerService': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerXFire': Cannot resolve reference to bean 'customerService' while setting bean property 'serviceBean'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerService': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
	at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:212)


 */

beans = {
    userSessionBean(com.cgah.UserUtil) { bean ->
        bean.scope = "session"
        bean.autowire = "byName"
	}


/*    jmsConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory){ bean ->
        bean.destroyMethod ="stop"
        connectionFactory(org.apache.activemq.ActiveMQConnectionFactory) {
            brokerURL = "tcp://localhost:61616"
        }
    }*/

    jmsFactory(org.apache.activemq.ActiveMQConnectionFactory)
    {
        brokerURL = "tcp://localhost:61616"
    }

    jmsTemplate(org.springframework.jms.core.JmsTemplate)
    {
        connectionFactory = jmsFactory
    }


    jmsListingMessageListener(MessageListenerAdapter, ref("listingService")) {
        defaultListenerMethod = "onNewListing"
    }
/*
    jmsEmailMessageListener(MessageListenerAdapter, ref("listingService")) {
        defaultListenerMethod = "onNewListing"
    }*/

    jmsMailMessageListener(MessageListenerAdapter, ref("listingService")) {
        defaultListenerMethod = "onNewListing"
    }

    jmsListingContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) {
            connectionFactory = jmsFactory //jmsConnectionFactory
            destinationName = "com.cgah.listing.queue"
            messageListener = jmsListingMessageListener
            transactionManager = ref("transactionManager")
            autoStartup = true
        }


     jmsListingMailContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) {
            connectionFactory = jmsFactory //jmsConnectionFactory
            destinationName = "listingQueue"
            messageListener = jmsMailMessageListener
            transactionManager = ref("transactionManager")
            autoStartup = true
        }
/*
    userSessionBean(com.cgah.CustomerService) { bean ->

        bean.scope = ""
        bean.autowire = "byName"

        
    }
*/
    // DO NOT CHANGE THIS!  ALL THE FRACKING UNIT TESTS AND A BUNCH OF STUFF WILL BREAK
    // IF YOU CHANGE THIS YOU WILL NEED TO CHANGE ALL THE CLASSES THAT ARE CHECKING FOR
    // PLAIN TEXT PASSWORD.  I KNOW IT'S STUPID BUT STUPID IS AS STUPID WAS FOR THIS SCHOOL ASSIGNMENT
    passwordEncoder(org.springframework.security.authentication.encoding.PlaintextPasswordEncoder)

}
